unit UDM;

interface

uses
  System.SysUtils, System.Classes, UniProvider, InterBaseUniProvider, Data.DB,
  DBAccess, Uni, SQLiteUniProvider;

type
  TDM = class(TDataModule)
    InterBaseUniProvider: TInterBaseUniProvider;
    ConnSrvDBRemote: TUniConnection;
    ConnSqliteDB: TUniConnection;
    SQLiteUniProvider1: TSQLiteUniProvider;
    ConnSrvDB: TUniConnection;
    procedure DataModuleCreate(Sender: TObject);
    procedure DataModuleDestroy(Sender: TObject);
  private
    { Private declarations }

    function ConnLocalSrvDB: Boolean;
  public
    { Public declarations }
  end;

var
  DM: TDM;

implementation

uses
  UCommonConst, UCommonFunSqlite;

{%CLASSGROUP 'Vcl.Controls.TControl'}

{$R *.dfm}

function TDM.ConnLocalSrvDB: Boolean;
var
  sDBFilePath, sConnSQL: string;
const
  DBNAME = 'splc.db';
begin
  sConnSQL := 'Provider Name=SQLite;Database=%s;Client Library=sqlite3.dll;Use Unicode=True;Login Prompt=False';


  sDBFilePath := GetExePath + 'DB\' + DBNAME;

  ConnSqliteDB.ConnectString := Format(sConnSQL, [sDBFilePath]);

  try
    ConnSqliteDB.Connected := True;
    Result := True;
  except
    Result := False;
  end;
end;

procedure TDM.DataModuleCreate(Sender: TObject);
begin
  if not ConnLocalSrvDB then
  begin
    MsgBoxDefault(RESCONNREMOTESRVDBFAIL);
    Halt(0);
  end;
end;

procedure TDM.DataModuleDestroy(Sender: TObject);
begin
  if ConnSqliteDB.Connected then
    ConnSqliteDB.Disconnect;
end;

end.

